package com.woniuxy.mesboot.controller;


import com.woniuxy.mesboot.entity.MesOutList;

import com.woniuxy.mesboot.service.MesOutListService;
import com.woniuxy.mesboot.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("mesoutlist")
public class MesOutListController {
    @Resource
    private MesOutListService mesOutListService;
    @GetMapping
    public Result queryAll(){
       List<MesOutList>mesOutLists=mesOutListService.selectAll();
       return  Result.ok().data("list",mesOutLists);

    }

    @PostMapping()
    public Result insert(@RequestBody MesOutList mesOutList) {
         int i=mesOutListService.insertSelective(mesOutList);
         if(i>0){
             return Result.ok("添加成功");
         }else{
             return Result.error("添加失败");
         }


    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        MesOutList mesOutList = mesOutListService.selectByPrimaryKey(id);
        return Result.ok().data("item", mesOutList);

    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        int i = mesOutListService.deleteByPrimaryKey(id);
        if (i > 0) {
            return Result.ok("删除成功");

        } else {
            return Result.error("删除失败");
        }


    }

    @PutMapping
    public Result update(@RequestBody MesOutList orders) {
        int i = mesOutListService.updateByPrimaryKeySelective(orders);
        if (i > 0) {
            return Result.ok("修改成功");

        } else {
            return Result.error("修改失败");
        }
    }
}
